package cn.zhiwen.reflectController;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class ReflectDemo06 {
    //泛型用在编译期，编译过后泛型擦除（消失掉）。所以是可以通过反射越过泛型检查的
    public static void main(String[] args) {
        try {
            List<String> strings = new ArrayList<>();
            strings.add("wuzhiwen");
            strings.add("dashuaige");

            Class aClass = strings.getClass();
            Method add = aClass.getMethod("add", Object.class);
            add.invoke(strings,123);

            strings.forEach(p ->System.out.print(p));

        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
